package com.weitu.permission.log.controller;

import com.weitu.base.controller.BaseController;
import com.weitu.paging.DataGridPagination;
import com.weitu.permission.log.entity.HandleLog;
import com.weitu.permission.log.entity.LoginLog;
import com.weitu.permission.log.service.LogService;
import com.weitu.plugin.PageView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by smp on 2017/3/20.
 */
@Controller
@RequestMapping(value = "permission/log")
public class LogController extends BaseController{
    private static final String MODULE_BATH_PATH=BASE_JSP_PATH+"permission/log";
    private final LogService logService;

    @Autowired
    public LogController(LogService logService){
        this.logService=logService;
    }

    /**
     * 跳转到操作日志页面
     * @return
     */
    @RequestMapping(value = "/handleLogList",method = RequestMethod.GET)
    public String handleLogList(){
        return  MODULE_BATH_PATH+"/handleLogList";
    }

    /**
     * 操作日志页面列表数据
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/handleLogList",method = RequestMethod.POST)
    public Object handleLogListAjax(HttpServletRequest request){
        Map<String, Object> paramMap = new HashMap<String, Object>();
        putParametersIntoMap(paramMap);

        int count=this.logService.queryHandleLogCount(paramMap);
        DataGridPagination dataGridPagination = DataGridPagination.getInstance(request, count);

        PageView pageView = dataGridPagination.getPageView();//生成pageView分页对象
        paramMap.put("pageView", pageView);
        List<HandleLog> dataList = this.logService.queryHandleLogList(paramMap);//获取列表数据

        return dataGridPagination.flushDataGridData(dataList);
    }

    /**
     * 调到登录日志页面
     * @return
     */
    @RequestMapping(value = "/loginLogList",method = RequestMethod.GET)
    public String loginLogList(){
        return MODULE_BATH_PATH+"/loginLogList";
    }

    /**
     * 登录日志列表数据
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/loginLogList",method = RequestMethod.POST)
    public Object loginLogListAjax(HttpServletRequest request){
        Map<String, Object> paramMap = new HashMap<String, Object>();
        putParametersIntoMap(paramMap);

        int count=this.logService.queryLoginLogCount(paramMap);
        DataGridPagination dataGridPagination = DataGridPagination.getInstance(request, count);

        PageView pageView = dataGridPagination.getPageView();//生成pageView分页对象
        paramMap.put("pageView", pageView);
        List<LoginLog> dataList = this.logService.queryLoginLogList(paramMap);//获取列表数据

        return dataGridPagination.flushDataGridData(dataList);
    }
}
